package ai.zixing.example02;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 */
public class GobangFactory {

    // 享元池
    private static Map<String, GobangFlyweight> pool;

    // 享元池
    private GobangFactory() {
        pool = new HashMap<>();
        GobangFlyweight black = new BlackGobang();
        GobangFlyweight write = new WhiteGobang();
        pool.put("b", black);
        pool.put("w", write);
    }


    public static GobangFactory getInstance() {
        return SingletonHolder.INSTANCE;
    }


    private static class SingletonHolder{
        private static final GobangFactory INSTANCE = new GobangFactory();
    }

    public GobangFlyweight getGoBang(String key) {
        return pool.get(key);
    }

}
